/***************************************************************************//**
 * @file MSc_Base.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/
#ifndef MSC_BASE_H
#define MSC_BASE_H

////////////////////////////////////////////////////////////////////////////////

#ifndef _USE_MATH_DEFINES
#   define _USE_MATH_DEFINES
#endif

////////////////////////////////////////////////////////////////////////////////

#include "MSc_Defs.h"

#include <utils/MSc_DataNode.h>
#include <utils/MSc_DataRef.h>
#include <utils/MSc_Exception.h>

////////////////////////////////////////////////////////////////////////////////

/** FDM base class. */
class MSc_Base
{
public:

    enum { L = 0, M, N };
    enum { P = 0, Q, R };
    enum { U = 0, V, W };
    enum { X = 0, Y, Z };

    /** Constructor. */
    MSc_Base( MSc_DataNode *rootNode = 0 ) :
        m_rootNode( rootNode )
    {
        if ( m_rootNode == NULL )
        {
            MSc_Exception e;

            e.setType( MSc_Exception::NullPointer );
            e.setFile( __FILE__ );
            e.setLine( __LINE__ );
            e.setInfo( "m_rootNode == NULL" );

            throw e;
        }
    }

    /** Destructor. */
    virtual ~MSc_Base() {}

    /** @return MSCFDM_SUCCESS on success or MSCFDM_FAILURE on failure. */
    inline int addDataRef( std::string path, MSc_DataNode::Type type )
    {
        return m_rootNode->addNode( path, type );
    }

    /**
     * Returns data reference of the data node
     * @param path data node path relative to the root node
     * @return data reference of the data node
     */
    inline MSc_DataRef getDataRef( std::string path )
    {
        return MSc_DataRef( m_rootNode->getNode( path ) );
    }

private:

    MSc_DataNode *m_rootNode;   ///< data tree root node

    /** Using this constructor is forbidden. */
    MSc_Base( const MSc_Base & ) {}
};

////////////////////////////////////////////////////////////////////////////////

#endif // MSC_BASE_H
